package com.raul.prueba.WSBlackjack;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.raul.prueba.WSBlackjack.vo.VOLogin;

/**
 * Servlet implementation class JugadorServlet
 */
public class JugadorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public JugadorServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String accion = request.getParameter("accion");
        List<VOLogin> lista = (List<VOLogin>) request.getSession().getAttribute("Listajugadores");
        VOLogin vo = new VOLogin();
        vo.setNombre(request.getParameter("Nombre"));
        vo.setDinero(Integer.parseInt(request.getParameter("Dinero")));
        vo.setCrupier(request.getParameter("Crupier"));
        if (accion.equals("guardar")) {
                lista.add(vo);
        } else if (accion.equals("eliminar")) {
                for (VOLogin obj : lista) {
                        if (obj.getNombre().equals(vo.getNombre())) {
                                lista.remove(obj);
                                break;
                        }
                }
        } else if (accion.equals("actualizar")) {
                for (VOLogin obj : lista) {
                        if (obj.getNombre().equals(vo.getNombre())) {
                                obj.setDinero(vo.getDinero());
                                break;
                        }

                }
        }
        response.sendRedirect("inicio.jsp");
        
	}
}